package family

import (
	"fmt"

	"gitee.com/zht639/my_gopkg/strtrans"
)

// 检查输入是否为数字
func checkNum() float64 {
	var num string
	for {
		fmt.Scanln(&num)
		new_num, err := strtrans.ToFloat(num)
		if err != nil {
			fmt.Printf("\t输入必须是数字！请重新输入：")
		} else {
			return new_num
		}
	}
}

// 检查输入是否为整数
func checkInt() int {
	num := strtrans.ToString(checkNum())
	for {
		new_num, err := strtrans.ToInt(num)
		if err != nil {
			fmt.Printf("\t输入必须是整数！请重新输入：")
		} else {
			return new_num
		}
		fmt.Scanln(&num)
	}
}

// 检查输入金额是否合理
func checkMoney(Type string, balance float64) float64 {
	for {
		money := checkNum()
		if money < 0 {
			fmt.Printf("\t输入不能小于0！请重新输入：")
		} else if money == 0 {
			fmt.Printf("\t无效的交易！请重新输入：")
		} else if Type == outcome && balance < money {
			fmt.Printf("\t支出不能超过余额！请重新输入：")
		} else {
			return money
		}
	}
}
